package com.example.libary.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Knife4j接口文档配置类
 */
@Configuration
public class Knife4jConfig {
    
    /**
     * OpenAPI配置
     */
    @Bean
    public OpenAPI openAPI() {
        return new OpenAPI()
                .info(new Info()
                        .title("图书管理系统API文档")
                        .description("图书管理系统接口文档")
                        .version("1.0.0")
                        .contact(new Contact().name("Admin").email("admin@example.com"))
                )
                // 添加JWT认证
                .components(new Components()
                        .addSecuritySchemes("Authorization", new SecurityScheme()
                                .type(SecurityScheme.Type.HTTP)
                                .scheme("bearer")
                                .bearerFormat("JWT")
                                .in(SecurityScheme.In.HEADER)
                                .name("Authorization")
                                .description("JWT认证token，格式为: Bearer {token}")
                        )
                )
                .addSecurityItem(new SecurityRequirement().addList("Authorization"));
    }
} 